package com.xbai.user.controller;

import com.xbai.user.domain.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author jxbai
 * @desc
 * @date 2021/1/14 0014
 */
@RestController
@RequestMapping("/user")
public class UserController {

    private static final Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private HttpServletRequest request;

    @GetMapping("/{userName}")
    public User getUserByUserName(@PathVariable("userName") String userName) {

        logger.info("Get user by userName from port : {} of user-service instance", request.getServerPort());

        User user = new User();
        user.setId(001L);
        user.setUserCode("mockUser");
        user.setUserName(userName);
        return user;
    }
}
